package com.terry.gamehall.test;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CompletableFutureTest2 {
    public static ExecutorService executor = Executors.newFixedThreadPool(10);
    public static void main(String[] args) throws Exception{
        //线程串行化
        //1.thenRun  没有返回值
//        CompletableFuture<Void> future = CompletableFuture.supplyAsync(() -> {
//            System.out.println(Thread.currentThread().getId());
//            int i = 10 / 2;
//            System.out.println("运行结果 " + i);
//            return i;
//        }, executor).thenRunAsync(() -> {
//            System.out.println("");
//        }, executor);
//        2.thenAccept 能接受到上一步结果,没有返回值
//        CompletableFuture<Void> future = CompletableFuture.supplyAsync(() -> {
//            System.out.println(Thread.currentThread().getId());
//            int i = 10 / 2;
//            System.out.println("运行结果 " + i);
//            return i;
//        }, executor).thenAcceptAsync((res) -> {
//            System.out.println("");
//        }, executor);
//       3.thenApply 能接受到上一步结果,有返回值
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getId());
            int i = 10 / 2;
            System.out.println("运行结果 " + i);
            return i;
        }, executor).thenApplyAsync(res -> {
            System.out.println("");
            return 0;
        }, executor);
        future.get();
    }
}
